<admintpl file="header"/>
</head>
<body>
<div class="wrap">
    <ul class="nav nav-tabs">
        <li><a href="{:U('Admin/News/index')}">新闻列表</a></li>
        <li class="active"><a href="{:U('Admin/News/add')}">修改{$Title}</a></li>
    </ul>
    <form method="post" class="form-horizontal js-ajax-form" id="form.js-ajax-forms"
          action="{:U('Admin/News/PicturePost')}">
        <div class="control-group">
            <label class="span1 control-label" style="width: 90px;">关键字：</label>
            <div class="span3">
                <input type="text" name="newsKey" value="{$news['keyWords']}" style="width: 556px;">
            </div>
        </div>
        <div class="control-group">
            <label class="span1 control-label" style="width: 90px;">新闻标题：</label>
            <div class="span3">
                <input type="text" name="newsTitle" value="{$news['title']}" style="width: 556px;">
            </div>
        </div>
        <div class="control-group">
            <label class="span1 control-label" style="width: 90px;">新闻来源：</label>
            <div class="span3">
                <input type="text" name="newsSource" value="{$news['source']}" style="width: 556px;">
            </div>
        </div>
        <div class="control-group">
            <label class="span1 control-label" style="width: 90px;">新闻分类：</label>
            <div class="span3">
                <select class="select_2" name="category" id="category">
                    <option>全部</option>
                    <foreach name="category" item="vo">
                        <option value="{$vo.cId}">{$vo.cN}</option>
                    </foreach>
                </select>
            </div>
            <label class="span1 control-label" style="width: 90px;">分类标签：</label>
            <div class="span3">
                <select class="select_2" name="tags" id="tags">
                    <option value="0">全部</option>
                </select>
            </div>
        </div>
        <div class="control-group">
            <label class="span1 control-label" style="width: 90px;">所属地区：</label>
            <div class="span3">
                <select class="select_2" name="province" id="province">
                    <option>全部</option>
                    <foreach name="province" item="vo">
                        <option value="{$vo.aId}">{$vo.aN}</option>
                    </foreach>
                </select>
            </div>
            <div class="span3">
                <select class="select_2" name="city" id="city">
                    <option value="0">全部</option>
                </select>
            </div>
        </div>
        <div class="control-group">
            <label class="span2 control-label" style="width: 90px;">图片：</label>
            <div class="span7">

                <div class="span2" style=" vertical-align:bottom">
                    <input type="hidden" value="1" name="pictureCount" id="pictureCount">
                    <input type="hidden" value="1" name="pictureMax" id="pictureMax">
                    <a style="font-size: 15px" onclick="copyHtml()">添加+</a>
                </div>
            </div>
        </div>
        <php>$i=1;</php>
        <foreach name="imgData" item="vo">
            <div class="control-group">
                <div class="span7" style="margin-left: 130px;">
                    <table>
                        <tr>
                            <td colspan="2">
                                <input type="text" style="width: 515px;" name="pictureTag[]" value="{$vo['title']}">
                            </td>
                        </tr>
                        <tr>
                            <td style="width: 135px">
                                <div style="text-align: left;">
                                    <input type="hidden" name="imageUrl[]" id="imageUrl{$i}" value="">
                                    <a href="javascript:void(0);"
                                       onclick="flashupload('thumb_images', '附件上传','imageUrl{$i}',thumb_images,'1,jpg|jpeg|gif|png|bmp,1,,,1','','','');return false;">
                                        <img src="{$vo['imgUrl']}" id="imageUrl{$i}preview"
                                             width="135"
                                             style="cursor: hand"/>
                                    </a>
                                </div>
                            </td>
                            <td>
                                <textarea style="width: 380px" name="pictureDesc[]" rows="6" placeholder="图片描述">{$vo['imgDesc']}</textarea>
                            </td>
                        </tr>
                    </table>
                </div>
                <div class="span2" style=" vertical-align:bottom">
                    <a style="font-size: 25px" onclick="removeHtml(this)">删除</a>
                </div>
            </div>
            <php>$i=$i+1;</php>
        </foreach>

        <div class="control-group" id="pictureHtml" style="display:none ">
            <div class="span7" style="margin-left: 130px;">
                <table>
                    <tr>
                        <td colspan="2">
                            <input type="text" style="width: 515px;" name="pictureTag[]" placeholder="图片标签">
                        </td>
                    </tr>
                    <tr>
                        <td style="width: 135px">
                            <div style="text-align: left;">
                                <input type="hidden" name="imageUrl[]" id="imageCopy" value="">
                                <a href="javascript:void(0);"
                                   onclick="flashupload('thumb_images', '附件上传','imageCopy',thumb_images,'1,jpg|jpeg|gif|png|bmp,1,,,1','','','');return false;">
                                    <img src="__TMPL__Public/assets/images/default-thumbnail.png"
                                         id="imageCopy_preview"
                                         width="135"
                                         style="cursor: hand"/>
                                </a>
                            </div>
                        </td>
                        <td>
                                <textarea style="width: 380px" name="pictureDesc[]" rows="6"
                                          placeholder="图片描述"></textarea>
                        </td>
                    </tr>
                </table>
            </div>
            <div class="span2" style=" vertical-align:bottom">
                <a style="font-size: 25px" onclick="removeHtml(this)">删除</a>
            </div>
        </div>
        <div class="form-actions" style="padding-left:260px;">
            <button type="submit" class="btn btn-primary js-ajax-submit">保存</button>
            &nbsp;&nbsp;<a class="btn" href="{:U('Admin/News/index')}">{:L('BACK')}</a>
        </div>
    </form>
</div>
<script src="__PUBLIC__/js/common.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/content_addtop.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        var flag = true;
        $('#province').change(function () {
            $.get('{:U("Admin/News/getCity")}' + '&pid=' + $('#province').val(), function (data) {
                var html = '<option value="0">--无--</option>';
                if (data['state'] == "success") {
                    html = '<option value="0">全部</option>';
                    for (var a in data.data) {
                        html += '<option value="' + data.data[a].aId + '">' + data.data[a].aN + '</option>';
                    }
                }
                $('#city').html(html);
                if (flag) {
                    $('#city').val("{$news['areaId']}");
                }
                flag = false;
            });
        });
        $('#province').val("{$news['provinceId']}");
        $('#province').change();

        var cateFlag=true;
        $('#category').change(function () {
            $.get('{:U("Admin/News/getTags")}' + '&cId=' + $('#category').val(), function (data) {
                var html = '<option value="0">--无--</option>';
                if (data['state'] == "success") {
                    html = '<option value="0">全部</option>';
                    for (var a in data.data) {
                        html += '<option value="' + data.data[a].tagId + '">' + data.data[a].tagName + '</option>';
                    }
                }
                $('#tags').html(html);
                if (cateFlag) {
                    $('#tags').val("{$news['subjectTagId']}");
                }
                cateFlag = false;
            });
        });
        $('#category').val("{$news['categoryId']}");
        $('#category').change();

    });
    function copyHtml() {
        var addHtml = $("#pictureHtml").html();

        var pictureMaxValue = $("#pictureMax").val();
        var newMaxValue = parseInt(pictureMaxValue) + 1;
        $("#pictureMax").val(newMaxValue);

        var newImgId = "imageUrl" + newMaxValue;
        var add2Html = addHtml.replace(new RegExp("imageCopy", "gm"), newImgId);
        add2Html = "<div class='control-group' id='pictureHtml" + newMaxValue + "'  >" + add2Html + "</div>";
        $("#pictureHtml").before(add2Html);

        var pictureCount = $("#pictureCount").val();
        var newCount = parseInt(pictureCount) + 1;
        $("#pictureCount").val(newCount);

    }
    function removeHtml($obj) {
        $($obj).parent().parent().remove();
        var pictureCount = $("#pictureCount").val();
        var newCount = parseInt(pictureCount) - 1;
        $("#pictureCount").val(newCount);
    }
</script>
</body>
</html>